package com.test.baiduai;


import com.baidu.aip.imageprocess.AipImageProcess;
import com.test.utils.Base64Utils;
import com.test.utils.FileUtil;
import org.apache.commons.io.FileUtils;
import org.json.JSONObject;

import java.io.File;
import java.util.HashMap;

public class ImageClean {
    //设置APPID/AK/SK
    public static final String APP_ID = "26061112";
    public static final String API_KEY = "mUf09IrFhi3ZGLq6dIeUju38";
    public static final String SECRET_KEY = "j6x4fthhdzj7nha2mZLT3Oy61peLfrgK";

    public static void main(String[] args) throws Exception {
        // 初始化一个AipImageProcess
        AipImageProcess client = new AipImageProcess(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 调用接口
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();

        // 参数为本地路径
        String image = "D:\\资料\\美国绘画透视完全教程\\029.jpg";
        JSONObject res = client.imageDefinitionEnhance(image, options);
        String base64 = res.getString("image");
        byte[] bytes = Base64Utils.decode2Bytes(base64);
        FileUtils.writeByteArrayToFile(new File("D:\\资料\\美国绘画透视完全教程\\029_clean.jpg"), bytes);
        System.out.println(res.toString(2));

    }

}
